//
//  FenLeiDDetailViewController.m
//  Experss
//
//  Created by wmwMAC on 17/8/3.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "FenLeiDDetailViewController.h"
#import "NoBuyDetailTwoCell.h"
#import "NoBuyDetailThirdCell.h"
#import "NoBuyDetailFourCell.h"
#import "NoBuyDetailFiveCell.h"

#import "CustomGuiGeView.h"//规格视图
#import "CustomWuLiuView.h"//商品参数视图
#import "custonWuLiuTwoView.h"//物流视图
#import "InStoreController.h"//进入店铺

#import "CustomGgThirdView.h"//选择规格视图三级视图

#import "FenLeiSelectListModle.h"
#import "FenLeiExistListModle.h"

#import "TiJIaoDingDanViewController.h"
#import "NoBuyDetailOne.h"
#import "PingLunViewController.h"

@interface FenLeiDDetailViewController ()<UITableViewDelegate, UITableViewDataSource,SDCycleScrollViewDelegate,customGuiGetDelegate,customShangPinCanShuDelegate,customWuLiuTwoDelegate,customGgThirdViewDelegate>

{
    SDCycleScrollView *cycleScrollView;
    
    dispatch_source_t _timer;
    
    NSString *tempBtnTitle;//选择的规格参数
    
    
    NSString *goodsName;//商品名称
    NSString *sellPrice;//售卖价格
    NSString *relaPrice;//真实价格
    NSString *monthBuy;//月销量
    NSString *skuNum;//库存
    NSString *isgroupbuy;//是否为抢购商品； 0否 1是
    UIButton *settingBtn;//收藏按钮
    
    
    NSString *choosID2;//选择的skuid
    NSString *choosNum;//选择的商品数量
    
    NSString *endTimeStr;//限购的结束时间
}

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSArray *titA;//商品参数标题

//遮盖视图
@property (nonatomic, strong) UIView *maskView;
@property (nonatomic, strong)CustomGuiGeView *customGuiGeView;//规格
@property (nonatomic, strong)CustomWuLiuView *customWuLiuView;//参数
@property (nonatomic, strong)custonWuLiuTwoView *custonViewWuL;//物流


@property(strong,nonatomic)UIWebView *webV;//图文详情
@property(strong,nonatomic)UIScrollView *scrollV;


@property (nonatomic, strong)NSArray *imageArrayData;//请求的商品图片数组
@property (nonatomic, strong)NSArray *canshuArray;//存放商品参数数据
@property (nonatomic, strong)NSDictionary *shopInfoDic;//店铺信息
@property (nonatomic, strong)NSArray *commentArray;//评论列表


@property (nonatomic, strong)NSMutableArray *guigeArray;//后台返回的规格选择数组
//@property (nonatomic, strong)NSDictionary *moRenChooseDic;//默认选中的规格
@property (nonatomic, strong) FenLeiExistListModle *morenModle;

@property (nonatomic, strong)NSMutableArray *numsKindArray;//各种拼凑可能含有的情况


@property (nonatomic, strong)CustomGgThirdView *customGgThirdView;//三级规格视图


@end

@implementation FenLeiDDetailViewController

-(UIScrollView *)scrollV
{
    if (_scrollV == nil)
    {
        _scrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreen_Height)];
        _scrollV.contentSize = CGSizeMake(kScreenWidth, kScreen_Height * 2);
        //设置分页效果
        _scrollV.pagingEnabled = YES;
        //禁用滚动
        _scrollV.scrollEnabled = NO;
        
    }
    return _scrollV;
}
-(UIWebView *)webV
{
    if (_webV == nil)
    {
        _webV = [[UIWebView alloc]initWithFrame:CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height-64-44)];
        [self.webV loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]];
        
    }
    return _webV;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    _numsKindArray = [NSMutableArray array];
    _guigeArray = [NSMutableArray array];
    
     self.navigationItem.title = @"商品详情";
    
    [self configureNaBar];
    [self configureViewC];
    [self getGoodsDetailData];//获取数据
    _titA  = @[@"请选择规格",@"物流说明",@"商品参数"];
    tempBtnTitle  = @"请选择规格";
}
- (void)configureNaBar {
   
//    self.navigationController.navigationBar.translucent = NO;
    //设置导航栏按钮的边距
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame= CGRectMake(0, 0, 60, 30);
    [rightBtn setImage:[UIImage imageNamed:@"all_fanhui2"] forState:(UIControlStateNormal)];
    [rightBtn addTarget:self action:@selector(handleBackAxtion) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btn_left = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    UIBarButtonItem *negativeSpacerleft = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    /**
     width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和  边界间距为5pix，所以width设为-5时，间距正好调整为0；width为正数 时，正好相反，相当于往左移动width数值个像素
     */
    negativeSpacerleft.width = -20;
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacerleft, btn_left, nil];
    
    
    
    UIButton *informationCardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [informationCardBtn addTarget:self action:@selector(enterehzFilesVC:) forControlEvents:UIControlEventTouchUpInside];
    [informationCardBtn setImage:[UIImage imageNamed:@"fenlei_xiaoxi"] forState:UIControlStateNormal];
    informationCardBtn.frame = CGRectMake(0, 0, 32, 32);
    //[informationCardBtn sizeToFit];
    UIBarButtonItem *informationCardItem = [[UIBarButtonItem alloc] initWithCustomView:informationCardBtn];
    
    
    UIBarButtonItem *fixedSpaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fixedSpaceBarButtonItem.width = 15;
    
    
    settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //[settingBtn addTarget:self action:@selector(enterTeamCard:) forControlEvents:UIControlEventTouchUpInside];
    [settingBtn setImage:[UIImage imageNamed:@"shocuang"] forState:UIControlStateNormal];
      [settingBtn setImage:[UIImage imageNamed:@"shocuang2"] forState:UIControlStateSelected];
    [settingBtn addTarget:self action:@selector(handleShouCangBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    settingBtn.frame = CGRectMake(0, -5, 30, 30);
    UIBarButtonItem *settingBtnItem = [[UIBarButtonItem alloc] initWithCustomView:settingBtn];
    
    self.navigationItem.rightBarButtonItems  = @[informationCardItem,fixedSpaceBarButtonItem,settingBtnItem];
    
}

#pragma mark －＝－＝－＝收藏按钮的点击事件
- (void)handleShouCangBtnAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"goods_id":_goodsID,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
 [HttpRequest postWithURLString:POST(Shop_GoodsDetailEditGoodsFavorite) parameters:parameDic success:^(id responseObject) {
     if ([responseObject[@"ret"] intValue] != 200) {
         [[DSLHUD shareDSLHUD] showTextNoActivity:@"操作失败" timeLength:1.5];
         return ;
     }
     [self.view showTextNoActivity:responseObject[@"data"][@"msg"] timeLength:1.5];
     
 } failure:^(NSError *error) {
     
 }];
    
    
}
- (void)handleBackAxtion {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 配置视图控制器
//配置视图控制器
- (void)configureViewC {
    _tableView  = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height-64-15) style:(UITableViewStyleGrouped)];
    _tableView.separatorStyle = kSpNone;
    _tableView.dataSource = self;
    _tableView.delegate = self;
   // [self.view addSubview:_tableView];
    [_tableView registerNib:[UINib nibWithNibName:@"NoBuyDetailTwoCell" bundle:nil] forCellReuseIdentifier:@"NoBuyDetailTwoCell"];
    [_tableView registerNib:[UINib nibWithNibName:@"NoBuyDetailThirdCell" bundle:nil] forCellReuseIdentifier:@"NoBuyDetailThirdCell"];
    [_tableView registerNib:[UINib nibWithNibName:@"NoBuyDetailFourCell" bundle:nil] forCellReuseIdentifier:@"NoBuyDetailFourCell"];
    [_tableView registerNib:[UINib nibWithNibName:@"NoBuyDetailFiveCell" bundle:nil] forCellReuseIdentifier:@"NoBuyDetailFiveCell"];
      [_tableView registerNib:[UINib nibWithNibName:@"NoBuyDetailOne" bundle:nil] forCellReuseIdentifier:@"NoBuyDetailOne"];
    
    [self.view addSubview:self.scrollV];
    [self.scrollV addSubview:_tableView];
    [self.scrollV addSubview:self.webV];
    
    
    //设置UITableView 上拉加载
    self.tableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //上拉，执行对应的操作---改变底层滚动视图的滚动到对应位置
        //设置动画效果
        [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
            self.scrollV.contentOffset = CGPointMake(0, kScreen_Height);
        } completion:^(BOOL finished) {
            //结束加载
            [self.tableView.footer endRefreshing];
        }];
        
        
    }];
    
    //设置UIWebView 有下拉操作
    self.webV.scrollView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //下拉执行对应的操作
        self.scrollV.contentOffset = CGPointMake(0, 0);
        //结束加载
        [self.webV.scrollView.header endRefreshing];
    }];
    
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 45)];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width , 10)];
    lineView.backgroundColor = KShouYeBg;
    [footerView addSubview:lineView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake((kScreen_Width - 180) * 0.5, 20, 180, 17)];
    label.font = [UIFont systemFontOfSize:12 * kScreen_Width / 375];
    label.text = @"继续拖动，查看图文详情";
    label.textAlignment = NSTextAlignmentCenter;
    [footerView addSubview:label];
    UIImageView *img = [[UIImageView alloc] init];
    img.contentMode = UIViewContentModeScaleAspectFit;
    img.frame = CGRectMake(CGRectGetMinX(label.frame), CGRectGetMinY(label.frame),15, 15);
    img.image = [UIImage imageNamed:@"上箭头"];
    [footerView addSubview:img];
    self.tableView.tableFooterView = footerView;
    
    
    
    
    UIButton *buyCarBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    buyCarBtn.frame = CGRectMake(0, kScreen_Height - 50-64, kScreen_Width/2, 50);
    [buyCarBtn setTitle:@"加入购物车" forState:(UIControlStateNormal)];
    [buyCarBtn setBackgroundImage:[UIImage imageNamed:@"chengkuai"] forState:(UIControlStateNormal)];
    buyCarBtn.tag = 801;
    [buyCarBtn addTarget:self action:@selector(handleBottomBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:buyCarBtn];
    
    UIButton *buyBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    buyBtn.frame = CGRectMake(CGRectGetMaxX(buyCarBtn.frame), kScreen_Height - 50 -64, kScreen_Width/2, 50);
    [buyBtn setTitle:@"立即购买" forState:(UIControlStateNormal)];
    [buyBtn setBackgroundImage:[UIImage imageNamed:@"bg1"] forState:(UIControlStateNormal)];
    buyBtn.tag = 802;
    [buyBtn addTarget:self action:@selector(handleBottomBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:buyBtn];
    
    
    _customGuiGeView = [[CustomGuiGeView alloc] initWithFrame:CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height)];
    _customGuiGeView.delegate = self;
    [[UIApplication sharedApplication].keyWindow addSubview:_customGuiGeView];
    
    _customWuLiuView = [[CustomWuLiuView alloc] initWithFrame:CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height)];
    _customWuLiuView.delegate = self;
    [[UIApplication sharedApplication].keyWindow addSubview:_customWuLiuView];
    
    _custonViewWuL = [[custonWuLiuTwoView alloc] initWithFrame:CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height)];
    _custonViewWuL.delegate = self;
    [[UIApplication sharedApplication].keyWindow addSubview:_custonViewWuL];
    
    
    _customGgThirdView =[[CustomGgThirdView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, kScreen_Height)];
 
    _customGgThirdView.delegate = self;
    
    [[UIApplication sharedApplication].keyWindow addSubview:_customGgThirdView];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 1) {
        return 3;
    }else if (section ==2)
    {
        return 1;
    }
    else {
        return 1;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.section == 0) {
        self.tableView.rowHeight = UITableViewAutomaticDimension;
        self.tableView.estimatedRowHeight = 200;
        return self.tableView.rowHeight;
    }
    else if(indexPath.section == 1){
        return 60;
    }else if (indexPath.section == 2){
        self.tableView.rowHeight = UITableViewAutomaticDimension;
        self.tableView.estimatedRowHeight = 100;
        return self.tableView.rowHeight;
    }else {
        return 101;
    }
    
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(indexPath.section == 0){
        NoBuyDetailTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NoBuyDetailTwoCell"];
        cell.selectionStyle = kSeNone;
        cell.nameLB.text = goodsName;
        cell.sellpriceLB.text = [NSString stringWithFormat:@"¥%@",relaPrice];
        cell.relaLB.text = [NSString stringWithFormat:@"¥%@",sellPrice];
        cell.skuNumLB.text = [NSString stringWithFormat:@"库存 %@",skuNum];
        cell.sellNumLB.text = [NSString stringWithFormat:@"月销 %@",monthBuy];;
        
        
        return cell;
    }else if (indexPath.section == 1){
        
        NoBuyDetailThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NoBuyDetailThirdCell"];
        
        cell.selectionStyle = kSeNone;
        if (indexPath.row == 0) {
            cell.titLB.text = tempBtnTitle;//更新cell的内容
        }else {
            cell.titLB.text = _titA[indexPath.row];
        }
        
        return cell;
    }else if(indexPath.section == 2){
        NoBuyDetailFourCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NoBuyDetailFourCell"];
        cell.selectionStyle = kSeNone;
        
        //是否有商品评论
        if (_commentArray == nil || [_commentArray isKindOfClass:[NSNull class]] || _commentArray.count == 0) {
            cell.nameLB.hidden = YES;
            cell.timeLB.hidden = YES;
            cell.contentLB.hidden = YES;
            cell.photoImage.hidden = YES;
            cell.noneLB.hidden = NO;
            cell.contentLB.text = @"";
        }
        else {
            cell.noneLB.hidden = YES;
            cell.nameLB.hidden = NO;
            cell.timeLB.hidden = NO;
            cell.contentLB.hidden = NO;
            cell.photoImage.hidden = NO;
            [cell.photoImage sd_setImageWithURL:[NSURL URLWithString:[_commentArray firstObject][@"headimgurl"]]];
            cell.nameLB.text = [_commentArray firstObject][@"nickname"];
            cell.timeLB.text = [_commentArray firstObject][@"addtime"];
            cell.contentLB.text = [_commentArray firstObject][@"desc"];
            cell.numLB.text = [NSString stringWithFormat:@"评价(%lu)",(unsigned long)_commentArray.count];
        }
        
        return cell;
    }else {
        NoBuyDetailFiveCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NoBuyDetailFiveCell"];
        cell.selectionStyle = kSeNone;
        [cell.logoV sd_setImageWithURL:[NSURL URLWithString:_shopInfoDic[@"logo"]]];
        cell.nameLb.text = _shopInfoDic[@"shop_name"];
        cell.personLB.text = [NSString stringWithFormat:@"%@ 关注",_shopInfoDic[@"favorite"]];
        [cell.goInSuperMark addTarget:self action:@selector(handleGoInSuperMark:) forControlEvents:(UIControlEventTouchUpInside)];
        
        return cell;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            //弹出规格视图
            [self popOneView];
        }
        if (indexPath.row == 1) {
            //弹出物流说明视图
            [self popThirdView];
        }
        if (indexPath.row == 2) {
            //弹出商品参数
            [self popTwoView];
        }
        
    }
    if (indexPath.section == 2) {
        PingLunViewController *ping = [[PingLunViewController alloc] init];
        [self.navigationController pushViewController:ping animated:YES];
    }
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0){
        return 250;
    }
    else {
        return 10;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 10)];
    bgV.backgroundColor = KShouYeBg;

    
    
    if (section == 0) {
    
        CGRect rect = CGRectMake(0, 0, kScreen_Width, 250);
        
        NoBuyDetailOne *cell = [[UINib nibWithNibName:@"NoBuyDetailOne" bundle:nil] instantiateWithOwner:nil options:nil][0];
        
    
        
        cell.frame = rect;
        UIView * view = [[UIView alloc] initWithFrame:rect];
        
        [view addSubview:cell];
        
        if (cycleScrollView) {
            [cycleScrollView removeFromSuperview];
        }
        // 创建不带标题的图片轮播器
        cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreen_Width, 200) imageURLStringsGroup:nil];//最后设置占位
        
        cycleScrollView.imageURLStringsGroup = _imageArrayData;
        cycleScrollView.backgroundColor =[ UIColor clearColor];
        
        
        
        if ([isgroupbuy isEqualToString:@"1"]) {
            cell.bgTwoView.hidden = NO;
             cycleScrollView.showPageControl = NO;
          
            
            
            //如果是抢购商品
            NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"yyyy-MM-dd"];
            
            //获取现在的时间并且
            NSDate *endDate = [dateFormatter dateFromString:[self getyyyymmdd2]];
            
            NSDate *startDate = [NSDate date];
            
            NSTimeInterval timeInterval =[endDate timeIntervalSinceDate:startDate];
            
            if (_timer==nil) {
                __block int timeout = timeInterval; //倒计时时间
                
                if (timeout!=0) {
                    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                    _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
                    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
                    dispatch_source_set_event_handler(_timer, ^{
                        if(timeout<=0){ //倒计时结束，关闭
                            dispatch_source_cancel(_timer);
                            _timer = nil;
                            dispatch_async(dispatch_get_main_queue(), ^{
                                
                                cell.timeOneLB.text = @"00";
                                cell.timeTwoLB.text = @"00";
                                cell.timeThirdLB.text = @"00";
                            });
                        }else{
                            int days = (int)(timeout/(3600*24));
                            if (days==0) {
                                
                            }
                            int hours = (int)((timeout-days*24*3600)/3600);
                            int minute = (int)(timeout-days*24*3600-hours*3600)/60;
                            int second = timeout-days*24*3600-hours*3600-minute*60;
                            dispatch_async(dispatch_get_main_queue(), ^{
                                if (days==0) {
                                    
                                }else{
                                    
                                }
                                if (hours<10) {
                                    cell.timeOneLB.text = [NSString stringWithFormat:@"0%d",hours];
                                }else{
                                    cell.timeOneLB.text = [NSString stringWithFormat:@"%d",hours];
                                }
                                if (minute<10) {
                                    cell.timeTwoLB.text = [NSString stringWithFormat:@"0%d",minute];
                                }else{
                                    cell.timeTwoLB.text = [NSString stringWithFormat:@"%d",minute];
                                }
                                if (second<10) {
                                    cell.timeThirdLB.text = [NSString stringWithFormat:@"0%d",second];
                                }else{
                                    cell.timeThirdLB.text = [NSString stringWithFormat:@"%d",second];
                                }
                                
                            });
                            timeout--;
                        }
                    });
                    dispatch_resume(_timer);
                }
            }
            
            

            
            
          
            
            
            
        }
        if ([isgroupbuy isEqualToString:@"0"]) {
                cell.bgTwoView.hidden = YES;
                cycleScrollView.showPageControl = YES;
        }
       
        cycleScrollView.pageControlBottomOffset=-40;
        cycleScrollView.pageDotColor = KShouYeBg;
        cycleScrollView.currentPageDotColor = KBtnColor;
        cycleScrollView.autoScroll = NO;//不自动滚动
        cycleScrollView.delegate = self;
        
        
        [cell addSubview:cycleScrollView];
        bgV.backgroundColor = [UIColor whiteColor];
        [bgV addSubview:view];
    }
    
    
    return bgV;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 0.001;
}


- (void)popOneView {
    [UIView animateWithDuration:0.2 animations:^{

        _customGgThirdView.frame  =  CGRectMake(0, 0, kScreenWidth, kScreen_Height);

        
    }];
    
}
- (void)popTwoView {
    [UIView animateWithDuration:0.2 animations:^{
        _customWuLiuView.frame = CGRectMake(0, 0, kScreenWidth, kScreen_Height);

        
        
    }];
}
- (void)popThirdView {
    [UIView animateWithDuration:0.2 animations:^{
        _custonViewWuL.frame = CGRectMake(0, 0, kScreenWidth, kScreen_Height);
       
        
    }];
}
#pragma mark 弹出规格视图的代理事件
//第一个弹出视图,,如果只有一种规格的情况
- (void)clooseBtnAction :(UIButton *)sender{
    [UIView animateWithDuration:0.2 animations:^{
        _customGuiGeView.frame = CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height);
    }];
}
//确定购买
- (void)sureBuyBtnAction:(UIButton *)sender :(NSString *)btnTitle {
    [UIView animateWithDuration:0.2 animations:^{
        _customGuiGeView.frame = CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height);
    }];
    tempBtnTitle = btnTitle;//把点击产品参数的值赋值给中间参数，然后刷新
    //一个cell刷新
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:1];
    [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
}




#pragma mark －＝－＝－－＝－＝－＝规格弹出视图的代理事件－＝－＝

//第一个弹出视图，如果有三种规格
-(void)sureThirdViewBtnAction:(UIButton *)sender BackArray:(NSArray *)backArr{
    
    FenLeiExistListModle *model = backArr[0];
    choosNum = backArr[1];
    //NSString *allMoneyString = backArr[2];
    choosID2 = model.sku_id;
    
    
    
    tempBtnTitle = [NSString stringWithFormat:@"%@  x%@",[model.sku_key componentsJoinedByString:@","],backArr[1]];
    _customGgThirdView.frame = CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height);
  
    //一个cell刷新
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:1];
    [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    
}
- (void)remoPopViewBtnAction :(UIButton *)sender {
     _customGgThirdView.frame = CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height);
}





//第二个弹出视图
- (void)rePopShangpinXiangQingView:(UIButton *)sender {
    
    _customWuLiuView.frame = CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height);
}
//确定按钮
- (void)sureShangPinCanshuView:(UIButton *)sender {
    _customWuLiuView.frame = CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height);
    
}


//第三个视图

-(void)rePopWuLiuView:(UIButton *)sender {
    _custonViewWuL.frame = CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height);
    
}
- (void)sureWuLiuView:(UIButton *)sender {
    _custonViewWuL.frame = CGRectMake(0, kScreen_Height, kScreenWidth, kScreen_Height);
}







#pragma  mark 轮播图的点击代理事件
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    NSLog(@"----%ld",(long)index);
    
    
}
#pragma mark 导航栏按钮的点击事件

-(void)enterehzFilesVC :(UIBarButtonItem *)message {
    [self.view showTextNoActivity:@"我是消息按钮" timeLength:1];
    
    
}

- (void)enterTeamCard:(UIBarButtonItem *)coll {
    [self.view showTextNoActivity:@"我是收藏按钮" timeLength:1];
    
}


#pragma  mark 倒计时计算代码
-(NSString *)getyyyymmdd2{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
    [formatter setTimeZone:timeZone];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[endTimeStr integerValue]];
    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
    return confromTimespStr;
    
}


//http://bs.m0571.com/mobileapi/public/baishi/?service=Shop_GoodsDetail.GetGoodsDetail&userid=1&goods_id=13

#pragma mark －＝－＝－＝－＝－＝－＝获取商品详情数据
- (void)getGoodsDetailData {
    NSDictionary *saveDic = [SaveDataMethord readLoginData];


    NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"goods_id":_goodsID,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
  
    [HttpRequest getWithURLString:POST(Shop_GoodsDetailGetGoodsDetail) parameters:parameDic success:^(id responseObject) {
        NSLog(@"0--=-=%@",responseObject);
       
        if ([responseObject[@"ret"] intValue] != 200) {
            [[DSLHUD shareDSLHUD] showTextNoActivity:@"获取商品详情出错" timeLength:1.5];
            return ;
        }
        NSDictionary *dic = responseObject[@"data"][@"goods_data"];

        //图文详情
        NSString *textStr = dic[@"desc"];
        [_webV loadHTMLString:textStr baseURL:nil];
        
        isgroupbuy = [NSString stringWithFormat:@"%@",dic[@"isgroupbuy"]];
        if ([isgroupbuy isEqualToString:@"1"]) {
            endTimeStr = [NSString stringWithFormat:@"%@",dic[@"groupbuy"][@"end_time"]];
        }
        
        
        //商品参数View赋值
        _canshuArray = dic[@"goods_attr"];
        _customWuLiuView.titArray = _canshuArray;
        //商品图片轮播
        _imageArrayData = dic[@"image_list"];
        
        
        //商品名称 真实价格，出售价格，月销量，库存
        goodsName = dic[@"name"];
        monthBuy = dic[@"sale"];
        sellPrice = dic[@"one_sku_data"][@"market_price"];
        relaPrice = dic[@"one_sku_data"][@"sell_price"];
        skuNum = dic[@"one_sku_data"][@"store_nums"];
        
        
        //店铺信息
        _shopInfoDic = responseObject[@"data"][@"shop"];
        
        //评论列表
        _commentArray = dic[@"comment"];
        
        
        //规格种类列表
        _guigeArray = [FenLeiSelectListModle mj_objectArrayWithKeyValuesArray:dic[@"spec_select_list"]];
        
        //默认选中的规格
        NSDictionary *morendic = dic[@"one_sku_data"];
        _morenModle = [FenLeiExistListModle mj_objectWithKeyValues:morendic];
        _numsKindArray = [FenLeiExistListModle mj_objectArrayWithKeyValuesArray:dic[@"sku_list"]];//搭配方案

        
        choosID2 =dic[@"one_sku_data"][@"sku_id"];
        choosNum = dic[@"one_sku_data"][@"minimum"];
        
        // 选择规格view 赋值
        _customGgThirdView.array4 = _numsKindArray;
         _customGgThirdView.imgStr = dic[@"image"];
        _customGgThirdView.selectModle = _morenModle;
        _customGgThirdView.totalArray = _guigeArray.mutableCopy;
        
       
        if ([dic[@"isfavorite"] intValue] == 0) {
            settingBtn.selected = NO;
        }else {
            settingBtn.selected = YES;
        }
        
        
        NSArray *temA =dic[@"one_sku_data"][@"sku_key"];
        if (temA.count == 0) {
            tempBtnTitle =  [NSString stringWithFormat:@"x %@",dic[@"one_sku_data"][@"minimum"]];
        }else {
            NSString *titleST =[dic[@"one_sku_data"][@"sku_key"] firstObject];
            tempBtnTitle =  [NSString stringWithFormat:@"%@  x%@",titleST,dic[@"one_sku_data"][@"minimum"]];
        }
        
    
        
        [self.tableView reloadData];
    
    } failure:^(NSError *error) {
    
    }];
}









#pragma mark 进入商店的按钮的点击事件
//进店
- (void)handleGoInSuperMark:(UIButton *)sender {
    InStoreController *store = [[InStoreController alloc] init];
    store.shopID = _shopInfoDic[@"m_id"];
    [self.navigationController pushViewController:store animated:YES];
}

#pragma mark  -=-=--=-=-//加入购物车和购买按钮的点击事件
- (void)handleBottomBtnAction:(UIButton *)sender {
    

    //商品goods_id  sku_id num 为测试数据，应该改为_goodsID ,,,,,
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"goods_id":_goodsID,@"sku_id":choosID2,@"num":choosNum,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    
    
    //加入购物车
    if (sender.tag == 801) {
        
        [HttpRequest postWithURLString:POST(Shop_CartAddCart) parameters:parameDic success:^(id responseObject) {
            if ([responseObject[@"ret"] intValue] != 200) {
                [[DSLHUD shareDSLHUD] showTextNoActivity:@"加入购物车失败" timeLength:1.5];
                return ;
            }
            
          [[NSNotificationCenter defaultCenter] postNotificationName:@"refshIngShopCar" object:nil];
            
            
            
      [MBProgressHUD showText:responseObject[@"data"][@"msg"]];
        } failure:^(NSError *error) {
            
        }];
    }
    
    
    
    //购买
    if (sender.tag == 802) {
        
        TiJIaoDingDanViewController *ding = [[TiJIaoDingDanViewController alloc] init];
        ding.sku_id =choosID2;//单个商品的skuid
        ding.buy_type = @"sku";
        ding.buy_num = choosNum;
        [self.navigationController pushViewController:ding animated:YES];
        
    }
    
}




@end
